package com.poorstu.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.DynaActionForm;

import com.common.base.web.BaseAction;
import com.poorstu.manager.LoginMeg;
import com.poorstu.model.LoginMod;


public class LoginAction extends BaseAction {

	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) {
		try {
			DynaActionForm dyaction = (DynaActionForm)form;
			String userAccount = (String)dyaction.get("userName");
			String password = (String)dyaction.get("userpwd");
			LoginMeg loginMeg = (LoginMeg)getBean("loginMeg");
			LoginMod user = loginMeg.login(userAccount, password);
			if(user != null)
			{// userId 是身份证号
				request.getSession().setAttribute("allUserId", user.getId());
				request.getSession().setAttribute("roleId", user.getRoleId().getRoleId());
				request.getSession().setAttribute("userName", user.getName());
				request.getSession().setAttribute("powerList", user.getRoleId().getPowerList());
				return mapping.findForward("success");
			}
		    
				
			return mapping.findForward("failure");
		} catch (Exception e) {
			e.printStackTrace();
			return mapping.findForward("failure");
		}
		
	}

}
